package com.szit.adminclient.controller;

import com.szit.adminclient.feign.AdminFeign;
import com.szit.util.Result;
import com.szit.util.vo.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class AdminClientController {
    @Autowired
    private AdminFeign adminFeign;


    @ApiOperation(value = "登录" ,notes = "登录")
    @PutMapping("/loginAdmin")
    public Result loginAdmin(@RequestBody LoginUser loginUser){
        log.info("admin-client: loginAdmin");
        return adminFeign.login(loginUser);
    }

    @ApiOperation(value = "登出" ,notes = "登出")
    @PutMapping("/loginOutAdmin")
    public Result loginOutAdmin(String token){
        log.info("admin-client: loginOutAdmin");
        return adminFeign.loginOut(token);
    }

    @ApiOperation(value = "修改用户密码" ,notes = "修改用户密码")
    @PutMapping("/adminUserPassword")
    public Result modifyUserPassword(@RequestBody ModifyPasswordInfo modifyPasswordInfo){
        log.info("admin-client: modifyUserPassword");
        Result result =  adminFeign.updatePasswordByUsername(modifyPasswordInfo);
        return result;
    }

    @ApiOperation(value = "添加子用户" ,notes = "添加子用户")
    @PostMapping("/adminUser")
    public Result addUser(@RequestBody AdminUserInfo adminUserInfo){
        log.info("admin-client: addUser");
        return adminFeign.insertAdminUser(adminUserInfo);
    }

    @ApiOperation(value = "删除子用户" ,notes = "删除子用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",dataType = "String",required = true),
            @ApiImplicitParam(name = "userId",value = "目标ID",dataType = "int",required = true)
    })
    @DeleteMapping("/adminUser")
    public Result deleteUser(String token ,Integer userId){
        log.info("admin-client: deleteUser");
        return adminFeign.deleteAdminUserByUserId(token,userId);
    }

    @ApiOperation(value = "查询用户列表" ,notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int",required = false,defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页个数",dataType = "int",required = false,defaultValue = "10")
    })
    @GetMapping("/adminUser")
    public Result selectUser(String token,Integer pageNum,Integer pageSize){
        log.info("admin-client: selectUser");
        return  adminFeign.selectAllUser(token,pageNum,pageSize);
    }

    @ApiOperation(value = "添加权限" ,notes = "添加权限")
    @PostMapping("/adminPermission")
    public Result addAdminPermission(@RequestBody AdminPermissionInfo adminPermissionInfo){
        log.info("admin-client: addAdminPermission");
        return adminFeign.insertAdminPermission(adminPermissionInfo);
    }

    @ApiOperation(value = "删除权限" ,notes = "删除权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",dataType = "String",required = true),
            @ApiImplicitParam(name = "permissionId",value = "目标ID",dataType = "int",required = true)
    })
    @DeleteMapping("/adminPermission")
    public Result deleteAdminPermission(String token ,Integer permissionId){
        log.info("admin-client: deleteAdminPermission");
        return adminFeign.deletePermissionById(token,permissionId);
    }

    @ApiOperation(value = "修改权限" ,notes = "修改权限")
    @PutMapping("/adminPermission")
    public Result modifyAdminPermission(@RequestBody AdminPermissionInfo adminPermissionInfo){
        log.info("admin-client: modifyAdminPermission");
        return adminFeign.updatePermissionById(adminPermissionInfo);
    }

    @ApiOperation(value = "查询权限列表" ,notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int",required = false,defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页个数",dataType = "int",required = false,defaultValue = "10")
    })
    @GetMapping("/adminPermission")
    public Result selectAdminPermission(String token,Integer pageNum,Integer pageSize){
        log.info("admin-client: selectAdminPermission");
        return  adminFeign.selectAllPermission(token,pageNum,pageSize);
    }

    @ApiOperation(value = "添加角色" ,notes = "添加角色")
    @PostMapping("/adminRole")
    public Result addAdminRole(@RequestBody AdminRoleInfo adminRoleInfo){
        log.info("admin-client: addAdminRole");
        return adminFeign.insertAdminRole(adminRoleInfo);
    }

    @ApiOperation(value = "删除角色" ,notes = "删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",dataType = "String",required = true),
            @ApiImplicitParam(name = "roleId",value = "目标ID",dataType = "int",required = true)
    })
    @DeleteMapping("/adminRole")
    public Result deleteAdminRole(String token ,Integer roleId){
        log.info("admin-client: deleteAdminRole");
        return adminFeign.deleteRoleById(token,roleId);
    }

    @ApiOperation(value = "修改角色" ,notes = "修改角色")
    @PutMapping("/adminRole")
    public Result modifyAdminRole(@RequestBody AdminRoleInfo adminRoleInfo){
        log.info("admin-client: modifyAdminRole");
        return adminFeign.updateRoleById(adminRoleInfo);
    }

    @ApiOperation(value = "查询角色列表" ,notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int",required = false,defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页个数",dataType = "int",required = false,defaultValue = "10")
    })
    @GetMapping("/adminRole")
    public Result selectAdminRole(String token, Integer pageNum,Integer pageSize){
        log.info("admin-client: selectAdminRole");
        return  adminFeign.selectAllAdminRole(token,pageNum,pageSize);
    }

    @ApiOperation(value = "用户更改角色" ,notes = "用户更改角色")
    @PutMapping("/adminUserRole")
    public Result modifyAdminUserRole(@RequestBody AdminUserRoleInfo adminUserRoleInfo){
        log.info("admin-client: modifyAdminUserRole");
        return adminFeign.updateUserRoleByUserId(adminUserRoleInfo);
    }

    @ApiOperation(value = "用户解绑角色" ,notes = "用户解绑角色")
    @DeleteMapping("/adminUserRole")
    public Result deleteAdminUserRole(AdminUserRoleInfo adminUserRoleInfo){
        log.info("admin-client: deleteAdminUserRole");
        return adminFeign.deleteAdminUserRole(adminUserRoleInfo);
    }

    @ApiOperation(value = "角色更改权限" ,notes = "角色更改权限")
    @PutMapping("/adminRolePermission")
    public Result modifyAdminRolePermission(@RequestBody AdminRolePermissionInfo adminRolePermissionInfo){
        log.info("admin-client: modifyAdminRolePermission");
        return adminFeign.updateRolePermissionByRoleId(adminRolePermissionInfo);
    }

    @ApiOperation(value = "角色解绑权限" ,notes = "角色解绑权限")
    @DeleteMapping("/adminRolePermission")
    public Result deleteAdminRolePermission(AdminRolePermissionInfo adminRolePermissionInfo){
        log.info("admin-client: deleteAdminRolePermission");
        return adminFeign.deleteAdminRolePermission(adminRolePermissionInfo);
    }
}
